<template>
  <div class="addgood-content">
      <van-address-list v-model="chosenAddressId" :list="list"  @add="onAdd" @edit="onEdit" class="addresslist"/>
      <div class="noimg" v-if="noimg == 1">
        <img src="@/assets/img/none.png">
      </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      noimg:0,
      chosenAddressId: null,
      list: [
        // {
        //   id: "1",
        //   name: "张三",
        //   tel: "13000000000",
        //   address: "浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室"
        // },
        // {
        //   id: "2",
        //   name: "李四",
        //   tel: "1310000000",
        //   address: "浙江省杭州市拱墅区莫干山路 50 号"
        // }
      ]
    };
  },
  beforeCreate: function() {
    //创建前
  },
  activated() {
    this.getlist();
  },
  created: function() {
    this.getlist();

    //创建后
  },
  beforeMount: function() {
    //挂载前
  },
  mounted: function() {
    //挂载后
  },
  beforeUpdate: function() {
    //更新前
  },
  update: function() {
    //更新后
  },
  methods: {
    getlist() {
      let that = this;
      that.$toast.loading({
        message: "加载中..."
      });
      var Sukdata = {
        userId: localStorage.getItem("userid")
      };
      console.log(Sukdata);
      that.axios
        .post(
          that.baseUrl + "/address/addressList",
          that.Qs.stringify(Sukdata),
          {
            headers: {
              "Content-Type": "application/x-www-form-urlencoded"
            }
          }
        )
        .then(function(res) {
          if (res.request.status === 200) {
            if (res.data.meta.code == 200) {
              console.log(res.data,'addlist');
              if(res.data.data.list.length == 0){
                that.noimg = 1;
                that.$toast({
                  message:'暂无地址'
                })
              }
              that.list = res.data.data.list;
              for (let i = 0; i < res.data.data.list.length; i++) {
                that.list[i].tel = res.data.data.list[i].phone;
                that.list[i].address = res.data.data.list[i].addressParticulars;
              }
//            that.chosenAddressId = res.data.data.list[0].id;
              that.$toast.clear();
            } else if (res.data.meta.code == 501) {
            }
          }
        });
    },
    deletbtn(){

    },
    onAdd() {
      this.$router.push({
        name: "editAddress"
      });
    },
    onEdit(item, index) {
      let that = this
      that.$router.push({
        name:'editAddress',
        params:{
          // 'editadd':[that.list[index].id,that.list[index].name,that.list[index].address,that.list[index].detail,that.list[index].phone],
          'name':that.list[index].name,
          'id':that.list[index].id,
          'area':that.list[index].address,
          'detail':that.list[index].detail,
          'phone':that.list[index].phone
        }
      })
    }
  }
};
</script>
<style lang="scss" scoped>
.addgood-content {
  font-size: 0.3rem;
}
.addresslist{
    position: relative;
}
.deletbtn{
    position: absolute;
    top: 0;
    right: 2rem;
}

.noimg{
  width: 100%;
  img{
    width: 100%
  }
}
</style>
